package com.clkj.zhonghui.controller.topic;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.topic.TopicTag;
import com.clkj.zhonghui.service.topic.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：周佳润
 * @Date：2024/7/16 下午3:40
 */
@RestController
@RequestMapping(value = "/TopicOrVideoTag")
@Api(value = "/TopicOrVideoTag", tags = {"文章或视频标签管理"})
@CrossOrigin
public class TagController {

    @Autowired
    private TagService tagService;

    @PostMapping("/addTag")
    @ApiOperation(value = "添加视频文章的标签")
    public Result addTag(@ApiParam(name = "tagNames", value = "标签名") @RequestParam("tagNames") String tagNames) {
        try {
            tagService.addTag(tagNames);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    @PostMapping("/getTagList")
    @ApiOperation(value = "获取视频文章的标签列表")
    public Result getTagList() {
        try {
            List<TopicTag> list = tagService.getTagList();
            return new Result(true, StatusCode.OK, "操作成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    @PostMapping("/delTag")
    @ApiOperation(value = "删除视频文章的标签")
    public Result delTag(@ApiParam(name = "tagId", value = "标签id") @RequestParam("tagId") String ids) {
        try {
            tagService.delTag(ids);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }
}
